﻿using System;
using System.Collections.Generic;

namespace Basmus.Web.Topology
{
    internal class Application : IApplication
    {
        public IDomain Domain { get; private set; }

        public string AppVirtualPath { get; private set; }

        public bool RouteExistingFiles { get; private set; }

        public Application(IDomain domain, string appVirtualPath, bool routeExistingFiles=false)
        {
            Domain = domain;
            AppVirtualPath = appVirtualPath;
            RouteExistingFiles = routeExistingFiles;
        }

        private readonly List<Type> _types = new List<Type>();

        private readonly object _lock = new object();

        public IEnumerable<Type> TargetTypes()
        {
            return _types;
        }

        public void Add(Type targetType)
        {
            lock (_lock)
            {
                if (!_types.Contains(targetType))
                {
                    _types.Add(targetType);
                }
            }
        }

        public void Remove(Type targetType)
        {
            lock (_lock)
            {
                if (!_types.Contains(targetType))
                {
                    _types.Remove(targetType);
                }
            }
        }
    }
}
